# ui_base.py
import tkinter as tk
from tkinter import ttk, messagebox
import datetime
from categories import EXPENSE_CATEGORIES, INCOME_CATEGORIES
from typing import List

class UIBase:
    def __init__(self, root, db, analysis=None):
        self.root = root
        self.db = db
        self.analysis = analysis

    CATEGORY_LEVEL_MAP = {
        "大类": "main_category_expense",
        "中类": "middle_category_expense",
        "小类": "sub_category_expense"
    }

    LEVEL_KEY_MAP = {
        "大类": "main",
        "中类": "middle",
        "小类": "sub"
    }

    def _open_save_dialog(self, title, default_filename):
        """通用保存文件对话框"""
        from tkinter import filedialog
        return filedialog.asksaveasfilename(
            defaultextension=".csv",
            filetypes=[("CSV文件", "*.csv"), ("所有文件", "*.*")],
            title=title,
            initialfile=default_filename
        )